package com.lcq.demo.common.config;

import com.lcq.demo.entity.dynamodb.Music;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable;
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.iot.IotClient;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.sqs.SqsClient;

/**
 * @author 240701005
 */
@Configuration
@ConfigurationProperties(prefix = "amazon.aws")
@Getter
public class AWSConfig {

    @Value("${amazon.aws.bucketName}")
    private String bucketName;

    /**
     * DynamoDB Client
     */
    @Bean
    public DynamoDbClient dynamoDbClient() {
        return DynamoDbClient.builder()
                .region(Region.US_EAST_1)
                .build();
    }

    /**
     * DynamoDB EnhancedClient
     * 增强型Client
     */
    @Bean
    public DynamoDbEnhancedClient dynamoDbEnhancedClient() {
        return DynamoDbEnhancedClient.builder()
                .dynamoDbClient(dynamoDbClient())
                .build();
    }

    @Bean
    public DynamoDbTable<Music> musicTable() {
        return this.dynamoDbEnhancedClient().table("test_music", TableSchema.fromBean(Music.class));
    }

    /**
     * S3 Client
     */
    @Bean
    public S3Client s3Client() {
        return S3Client.builder()
                .region(Region.US_EAST_1)
                .build();
    }

    /**
     * SES Client
     */
    @Bean
    public SesClient sesClient() {
        return SesClient.builder()
                .region(Region.US_EAST_1)
                .build();
    }

    /**
     * SQS Client
     */
    @Bean
    public SqsClient sqsClient() {
        return SqsClient.builder()
                .region(Region.US_EAST_1)
                .build();
    }

    /**
     * IOT Client
     */
    @Bean
    public IotClient iotClient() {
        return IotClient.builder()
                .region(Region.US_EAST_1)
                .build();
    }

}
